<template>
	<view class="content">
		<view class="examine-header flex">
			<view class="examine-time" @click="onPicker('time')">
				{{pickerTimeText}} 
			</view>
			<view class="colora" v-show="is_pay ==1">
				已补贴
			</view>
		</view>
		<view class="examine-total bsp10">
			<view class="examine-total-text my_fc my_fs my_fw frcc">
				<text class="ha bsp10 frcc">总补贴: ￥{{amount ? amount : 0}} 元  </text>
				<text class="ha bsp10 frcc">税后补贴: ￥{{amount ? amount - fee : 0}} 元  </text>
			</view>
			<view class="colora tips my_fw bsp10">
				注意：业绩未达标的省级会自动上塑到上一级，不计入补贴计算
			</view>
		</view>
		<view class="examine-table">
			<view class="examine-li bsp10 frcc" :key="item.id" v-for="(item,index) in items">
				<image class="examine-li-img" :src="item.head_portrait?item.head_portrait:'../../../static/logo_abf.png'" mode="scaleToFill"></image>
				<view class="examine-li-info bsp10 fccs">
					<view class="">
						{{item.realname||item.nickname}}
					</view>
					<view class="">
						{{item.mobile}}
					</view>
				</view>
				<view class="examine-li-amount nobefore my_fc">
					￥{{item.amount}}
				</view>
			</view>
		</view>
		<uni-load-more :status="moreStatus" />
		<mpvue-picker :themeColor="themeColor" ref="mpvuePicker" :mode="mode" :deepLength="deepLength" :pickerValueDefault="pickerValueDefault"
		 @onConfirm="onConfirm" @onCancel="onCancel" :pickerValueArray="pickerValueArray"></mpvue-picker>
		<u-back-top :scroll-top="scrollTop" top="600" icon="arrow-up" tips="顶部"></u-back-top>
	</view>
</template>

<script>
	
	import {
        mapState,
        mapMutations
    } from 'vuex'
	import uniLoadMore from '@/components/uni-ui/uni-load-more/uni-load-more.vue'	
	import mpvuePicker from '../../../components/mpvue-picker/mpvuePicker.vue';
	
	export default {
		computed: {
            ...mapState(['token'])
        },
		components: {
			mpvuePicker,
			uniLoadMore
        },
		data() {
			return {
				pickerTimeArray: [],
				themeColor: '#007AFF',
				pickerTimeText: '',
				date: '',
				level: 1,
				mode: '',
				deepLength: 1,
				pickerValueDefault: [0],
				pickerValueArray:[],
				type: '',
				items: [],
				page: 1,
				pageCount: 0,		// 总页数
				moreStatus: 'more',
				loadingStatus: true,
				log: {},
				amount: 12044110,
				fee: 564,
				is_pay: 0,
				isShowLoading:false,
				isPullDownRefresh:false,
				scrollTop:0
			}
		},
		onShow() {
			this.pickerTimeArray = this.getYear()
			this.pickerTimeText = this.pickerTimeArray[0].label
			this.date = this.pickerTimeArray[0].value
			// 监听token登录状态请求会员信息
			if(this.token){
				this.isShowLoading=true
				this.showLoading()
				this.getTotalInfo()
				//this.getlist()				
			}
			if(this.items.length===0)this.moreStatus='noMore'
		},
		methods: {
			...mapMutations(['getNetworkType','vuexRequest']),
			getlist() {
				if(!this.token){
					return !1
				}
				if(!this.loadingStatus){	//防止重复请求
					return !1
				}
				//
				this.loadingStatus = false
				this.moreStatus = 'loading'
				this.vuexRequest({
					url: '/api/addons/execute?route=agent-allowance/index&addon=o-s-mall-dist&access-token=' + this.token,
					method: 'GET',
					data: {date:''+this.date+'',page:this.page,"per-page":20},
					success: (res)  => {
						this.loadingStatus = true
						// 
						if(this.page == 1){
							this.items = res.data.data.list
						}else{
							this.items = this.items.concat(res.data.data.list)
						}						
						if(this.isShowLoading){
							uni.hideLoading()
							this.isShowLoading=false
						}
						if(this.isPullDownRefresh){
							uni.stopPullDownRefresh()
							this.isPullDownRefresh=false
						}
						// 分页信息
						this.page++
						this.pageCount = res.data.data.pageInfo.pageCount
						// 判断分页
						if(this.page > this.pageCount){
							this.moreStatus = 'noMore'
						}else{
							this.moreStatus = 'more'
							this.loadingStatus = true
						}
					},
					fail: (err)  => {
					},
				})
			},
			showSinglePicker(array) {
				this.pickerValueArray = array
				this.mode = 'selector'
				this.deepLength = 1
				this.pickerValueDefault = [0]
				this.$refs.mpvuePicker.show()
			},
			onConfirm(e) {
				console.log(e.value)
				if(this.type == 'name'){
					this.pickerNameText = e.label
					this.level =  e.value
				}else if(this.type == 'time'){
					this.pickerTimeText = e.label
					this.date =  e.value
				}
				if(this.token){
					this.page = 1
					this.loadingStatus = true
					this.getlist()				
				}
			},
			onPicker(type) {
				this.type = type
				if(type == 'name'){
					this.showSinglePicker(this.pickerSingleArray)
				}else if(type == 'time'){
					this.showSinglePicker(this.pickerTimeArray)
				}
			},
			getYear() {
				let dataArr = [];
				let data = new Date();
				let year = data.getFullYear();
				data.setMonth(data.getMonth(), 1)//获取到当前月份,设置月份
				for (var i = 0; i < 500; i++) {
					data.setMonth(data.getMonth() - 1);//每次循环一次 月份值减1
					var m = data.getMonth() + 1;
					m = m < 10 ? "0" + m : m;
					dataArr.push({
						"label":data.getFullYear() + "-" + (m),
						"value":data.getFullYear() + "-" + (m)
					})
				}
				return dataArr
			},
			getTotalInfo(){
				this.vuexRequest({
					url:'/api/addons/execute?route=agent-allowance/count&addon=o-s-mall-dist',
					method:'GET',
					data:{'access-token':this.token,date:''+this.date+''},
					success:(res)=>{
						//console.log(res)
						this.amount=res.data.data.total_amount
						this.fee=res.data.data.fee
						
						//取消加载动作
						if(this.isShowLoading){
							this.hideLoading()
							this.isShowLoading=false
						}
						if(this.isPullDownRefresh){
							uni.stopPullDownRefresh()
							this.isPullDownRefresh=false
						}
					}
				})
			},
			showLoading(title='正在加载'){
				uni.showLoading({
					title:title
				})
			},
			hideLoading(){uni.hideLoading()}
		},
		onBackPress() {
			if (this.$refs.mpvuePicker.showPicker) {
				this.$refs.mpvuePicker.pickerCancel();
				return true;
			}
			 
		},
		onUnload() {
			if (this.$refs.mpvuePicker.showPicker) {
				this.$refs.mpvuePicker.pickerCancel()
			}
			
		},
		onPullDownRefresh() {
			this.page = 1
			this.isPullDownRefresh=true
			this.getlist()
			// 实际开发中通常是网络请求，加载完数据后就停止。这里仅做演示，加延迟为了体现出效果。
			/* setTimeout(() => {
				uni.stopPullDownRefresh();
			}, 2000); */
		},
		onReachBottom() {
			if(this.loadingStatus &&  this.pageCount > this.page ){	//防止重复请求
				this.getlist()
			}else{
				this.moreStatus = 'noMore'
			}
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		}
	}
</script>

<style scoped>
	/**/
	.my_fc{
		color: #d9001b;
	}
	.my_fs{
		font-size: 26rpx;
	}
	.my_mt{
		margin-top: 20rpx;
	}
	.my_fw{
		font-weight: bold;
	}
	/**/
	
	.flex{
		display: -webkit-box;
		display: -webkit-flex;
		display: -ms-flexbox;
		display: flex;
		-webkit-box-orient: horizontal;
		-webkit-box-direction: normal;
		-webkit-flex-direction: row;
		-ms-flex-direction: row;
		flex-direction: row;
		-webkit-box-pack: justify;
		-webkit-justify-content: space-between;
		-ms-flex-pack: justify;
		justify-content: space-between;
		-webkit-box-align: center;
		-webkit-align-items: center;
		-ms-flex-align: center;
		align-items: center;
	}
	.po{
		position: relative;
	}
	.po:after{
		position: absolute;
		z-index: 10;
		right: 0;
		bottom: 0;
		left: 0;
		height: 1px;
		content: '';
		-webkit-transform: scaleY(.5);
		-ms-transform: scaleY(.5);
		transform: scaleY(.5);
		background-color: #c8c7cc;
	}
	.examine-header{
		padding: 20upx ;
		color: #202020;
		position:sticky;
		top: 0;
		background-color: #f8f8f8;
		z-index: 100;
	}
	.colora{
		color: #e83e41;
	}
	.examine-time{
		position: relative;
		padding: 0 30upx 0 0;
	}
	.examine-time:after{
		position: absolute;
		content: '';
		display: block;
		width: 10upx;
		height: 10upx;
		border: solid 2upx #000000;
		right: 0;
		top: 50%;
		margin: -10upx 0 0 0 ;
		transform: rotate(45deg);
		border-left: 0;
		border-top: 0;
	}
	.examine-total{
		background: #FFFFFF;
		text-align: center;
		padding: 40rpx 0;
		/* border:1px solid rgba(0,0,0,.5) */
		box-shadow: 10rpx 10rpx 20rpx -10rpx rgba(0,0,0,.5);
	}

	.left{
		margin: 0 60upx 0 0 ;
	}
	.tips{
		padding: 10upx 0;
		font-size: 18upx;
	}
	.examine-table{
		background: #FFFFFF;
		position: relative;
	}
	.examine-table:before{
		position: absolute;
		content: '';
		display: block;
		background: #e8e8e8;
		height: 2upx;
		width: 100%;
		top: 0;
		-webkit-transform: scaleY(.5);
		-ms-transform: scaleY(.5);
		transform: scaleY(.5);
	}
	
	.examine-col{
		width: 33.333%;
		text-align: center;
		position: relative;
		padding: 20upx 0;
	}
	.examine-col.active text{
		position: absolute;
		display: block;
		width: 10upx;
		height: 10upx;
		border: solid 2upx #000000;
		right: 20%;
		top: 50%;
		margin: -10upx 0 0 0 ;
		transform: rotate(45deg);
		border-left: 0;
		border-top: 0;
	}
	.examine-col:before{
		position: absolute;
		content: '';
		display: block;
		background: #e8e8e8;
		width: 2upx;
		right: 0;
		top: 0;
		bottom: 0;
		-webkit-transform: scaleX(.5);
		-ms-transform: scaleX(.5);
		transform: scaleX(.5);
	}
	.examine-col:after{
		position: absolute;
		content: '';
		display: block;
		background: #e8e8e8;
		height: 2upx;
		width: 100%;
		bottom: 0;
		-webkit-transform: scaleY(.5);
		-ms-transform: scaleY(.5);
		transform: scaleY(.5);
	}
	.examine-col.nobefore:before{
		display: none;
	}
	
	.examine-li{
		padding: 20rpx;
	}
	
	.examine-li-img{
		width: 15vw;
		height: 15vw;
		border-radius: 3vw;
	}
	
	.examine-li-info{
		flex:1;
		padding:0 0 0 30rpx ;
	}
	
	.examine-li-amount{
		display: inline-block;
	}
</style>
